package logic

import (
	"context"
	"srv/models/mysql"
	"srv/models/redis"

	"srv/internal/svc"
	"srv/sesame"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LoginLogic) Login(in *sesame.LoginRequest) (*sesame.LoginResponse, error) {
	// todo: add your logic here and delete this line
	u := mysql.User{}
	err := u.GetUser(in.Phone)
	if err != nil {
		logx.Error("没有该手机号码")
		return nil, err
	}
	redis.Rdb.Get(context.Background(), "SendCode"+in.Phone)
	return &sesame.LoginResponse{
		UserId: int64(u.ID),
	}, nil
}
